// 引入mongoose

const mongoose = require("mongoose");

// 2.链接数据库

mongoose.connect("mongodb://localhost:27017/xdw", { useNewUrlParser: true, useUnifiedTopology: true })

// 3.获取链接 成功的对象

let db = mongoose.connection;

// 4.监听链接成功和连接失败的处理函数

db.on("open", () => {
    console.log("数据库链接成功");
})

    db.on("erro", err => {
        console.log(err);
    })

module.exports = mongoose;
